package com.zbkj.front.controller.publicly;

import com.zbkj.common.response.traceability.TraceabilityDetailResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.TraceabilityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 公开溯源查询控制器
 * +----------------------------------------------------------------------
 * | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 * +----------------------------------------------------------------------
 * | Author: xiaolic
 * +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@RequestMapping("api/public/trace")
@Api(tags = "商品溯源-公开查询接口")
public class TraceabilityPublicController {

    @Autowired
    private TraceabilityService traceabilityService;

    /**
     * 根据唯一溯源ID查询溯源详情
     * @param id 唯一溯源ID
     * @return 溯源详情
     */
    @ApiOperation(value = "根据唯一溯源ID查询溯源详情")
    @ApiImplicitParam(name = "id", value = "唯一溯源ID", required = true, dataType = "Long")
    @GetMapping("")
    public CommonResult<TraceabilityDetailResponse> queryTraceDetail(@RequestParam("id") Long id) {
        try {
            TraceabilityDetailResponse response = traceabilityService.queryTraceDetailByTraceId(id);
            return CommonResult.success(response);
        } catch (Exception e) {
            log.error("查询溯源详情失败: {}", e.getMessage());
            return CommonResult.failed(e.getMessage());
        }
    }
}
